package com.sgolub.commanndsonline.ws.dao;

import java.util.List;

import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.sgolub.commanndsonline.ws.entity.AdvertisingRegistryOperation;

/**
 * @author sgolub
 *
 */
@Repository
public class AdvertisingRegistryOperationDAOImpl implements AdvertisingRegistryOperationDAO {

    @Autowired
    private SessionFactory sessionFactory;
    
	public  AdvertisingRegistryOperation get(Integer id) {
		 AdvertisingRegistryOperation  advertisingRegistryOperation = ( AdvertisingRegistryOperation)sessionFactory.
								getCurrentSession().get( AdvertisingRegistryOperation.class, id);
		return advertisingRegistryOperation;
	}

	public void add( AdvertisingRegistryOperation advertisingRegistryOperation) {
		advertisingRegistryOperation.setOperationExecutedStatus(0);
		sessionFactory.getCurrentSession().save(advertisingRegistryOperation);

	}

	public void update( AdvertisingRegistryOperation advertisingRegistryOperation) {
		sessionFactory.getCurrentSession().update(advertisingRegistryOperation);

	}

	public void remove(Integer id) {
		sessionFactory.getCurrentSession().delete(get(id));
	}

	@SuppressWarnings("unchecked")
	public List<AdvertisingRegistryOperation> list() {
		return sessionFactory.getCurrentSession().createQuery("from  AdvertisingRegistryOperation").list();
	}
	
	@SuppressWarnings("unchecked")
	public List<AdvertisingRegistryOperation> listActive() {
		System.out.println("List<AdvertisingRegistryOperation> listActive()");
		return sessionFactory.getCurrentSession().createQuery("from  AdvertisingRegistryOperation where operationExecutedStatus = 0").list();
	}	

	@SuppressWarnings("unchecked")
	public List<AdvertisingRegistryOperation> filter() {
		return sessionFactory.getCurrentSession().createQuery("from  AdvertisingRegistryOperation").list();
	}

	
	
}
